//
//  HomeImageFilterCell.swift
//  WatermarkCamera
//
//  Created by Python on 2024/7/26.
//

import UIKit

class HomeImageFilterCell: UICollectionViewCell {
    
    
   private lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.adjustsFontSizeToFitWidth = true
        return label
    }()
    
    private lazy var imageView: UIImageView = {
        let imageView = UIImageView()
        imageView.contentMode = .scaleAspectFit
        return imageView
    }()
    
    private lazy var checkView: UIImageView = {
        let imgView = UIImageView()
        imgView.image = "icon_check_44".axc.uiImage
        return imgView
    }()
    
    var item: ImageFilterItem = .init() {
        didSet {
            imageView.image = item.image
            titleLabel.text = item.name
            titleLabel.textColor = item.isSelected ? UIColor.main : UIColor.black
            checkView.isHidden = !item.isSelected
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        createUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: UI
    private func createUI() {
        let imageWH = 44.0
        // imageView
        imageView.contentMode = .scaleAspectFill
        imageView.layer.cornerRadius = imageWH * 0.5
        imageView.clipsToBounds = true
        contentView.addSubview(imageView)
        imageView.snp.makeConstraints { make in
            make.top.equalToSuperview()
            make.width.height.equalTo(imageWH)
            make.centerX.equalToSuperview()
        }
        // checkView
        checkView.layer.cornerRadius = imageWH * 0.5
        checkView.clipsToBounds = true
        contentView.addSubview(checkView)
        checkView.snp.makeConstraints { make in
            make.edges.equalTo(imageView)
        }
        // 名称
        titleLabel.font = 13.axc.uiFont
        titleLabel.textAlignment = .center
        contentView.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.left.right.bottom.equalToSuperview()
        }
    }
}
